﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Manager;
using Model;
using ExtAspNet;
using Manager.CustomerHelper;
namespace HealthSystem.sysAdmin
{
    public partial class SendNotice : BasePage
    {
        HW_NoticeManager noticeManager = new HW_NoticeManager();
        public override ModuleType Module
        {
            get
            {
                return ModuleType.OrgManager;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnNew.OnClientClick += Window1.GetShowReference("Notice_New.aspx","新建通知");
                BindGrid();
            }
        }
        private void BindGrid()
        {
            int count = 0;
            var list= noticeManager.GetList(Grid1.PageIndex, Grid1.PageSize, out count);
            Grid1.RecordCount = count;
            Grid1.DataSource = list;
            Grid1.DataBind();
        }
        protected void Window1_Close(object sender, ExtAspNet.WindowCloseEventArgs e)
        {
            BindGrid();
        }
        protected void Row_Command(object sender, ExtAspNet.GridCommandEventArgs e)
        {
            if (e.CommandName == "send")
            {
                try
                {
                    int id = Convert.ToInt32(Grid1.Rows[e.RowIndex].DataKeys[0]);
                    int n=noticeManager.Send(id);
                    if (n > 0)
                    {
                        ExtAspNet.Alert.Show("消息已经发送");
                        BindGrid();
                    }
                }
                catch
                {
                    ExtAspNet.Alert.Show("发送消息错误");
                }
            }
        }
        protected void pageIndex_Change(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            BindGrid();
        }
    }
}